﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Nirvana
{
    public sealed class LogAppender
    {
        private List<ILogAppender> LogAppenderList = new List<ILogAppender>();

        public void Log(LogItem logItem)
        {
            foreach(var p in this.LogAppenderList)
            {
                p.AppendLog(logItem);
            }

            if(this.LogAppenderList.Count == 0)
            {
                switch (logItem.Severity)
                {
                    case LogSeverity.Warning:
                        Debug.LogWarning(logItem.Message, logItem.Context);
                        return;
                    case LogSeverity.Error:
                        Debug.LogError(logItem.Message, logItem.Context);
                        return;
                }
                Debug.Log(logItem.Message, logItem.Context);
            }
        }

        public void Add(ILogAppender log)
        {
            this.LogAppenderList.Add(log);
        }

        public bool Remove(ILogAppender log)
        {
            return this.LogAppenderList.Remove(log);
        }

        public void Clear()
        {
            this.LogAppenderList.Clear();
        }

    }
}

